﻿using BackData;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RBAC.API.Command.Permission;
using RBAC.API.DTOs;

namespace RBAC.API.Controllers
{
    /// <summary>
    /// 权限控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class PermissionsController : ControllerBase
    {
        IMediator mediator;

        public PermissionsController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 权限数据获取
        /// </summary>
        /// <param name="request">权限名称</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<List<PermissionDTO>>> PermissionGet([FromQuery]PermissionGetCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除权限信息
        /// </summary>
        /// <param name="request">权限主键</param>
        /// <param name="cancellationToken"></param>
        /// <returns>影响行数</returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPut]
        public async Task<ApiResult<int>> PermissionDel(PermissionDelCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 权限添加
        /// </summary>
        /// <param name="request">参数</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>影响行数</returns>
        [HttpPost]
        public async Task<ApiResult<int>> PermissionAdd(PermissionAddCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 权限修改
        /// </summary>
        /// <param name="request">参数</param>
        /// <param name="cancellationToken">取消</param>
        /// <returns>影响行数</returns>
        [HttpPut]
        public async Task<ApiResult<int>> PermissionUpdate(PermissionUpdateCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
